------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure6.log
  log type:  text
 opened on:  14 Jan 2019, 15:53:20

. #delimit ;
delimiter now ;
. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:      figure6.do                                      *;
. *       Date:           January 14, 2019                                *;
. *       Author:         MRG/CC                                          *;
. *       Purpose:        Produce Figure 6 for It's Not Only What You     *;
. *                       Say, It's Also How You Say It: The Strategic    *;
. *                       Use Of Campaign Sentiment. Journal of Politics. *;
. *                       Forthcoming.                                    *;
. *           Input File:     sentiment.dta                                   *;
. *       Output File:    figure6.log                                     *;
. *       Data Output:    none                                            *;
.              *       Previous file:  sentiment.dta                                   *;
. *       Machine:        desktop/laptop                                                  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *        Load data                                                      *;
. *     ****************************************************************  *;
. use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

. set more off;

. *     ****************************************************************  *;
. *       Declare data to be panel, where the panel is based on language  *;
. *     ****************************************************************  *;
. xtset language;
       panel variable:  language (unbalanced)

. xtsum positive_sentiment;

Variable         |      Mean   Std. Dev.       Min        Max |    Observations
-----------------+--------------------------------------------+----------------
positi~t overall |  1.696912   1.446166       -.68        7.6 |     N =     421
         between |              1.34797   .4018627     4.3828 |     n =       7
         within  |             .7198334  -1.565888   4.914112 | T-bar = 60.1429

. *     ****************************************************************  *;
. *       Generate additional variables that we will need for our         *;
. *       analysis.                                                       *;
. *     ****************************************************************  *;
. gen incumbent_inflation_l = incumbent*inflation_l;
(21 missing values generated)

. label var incumbent_inflation "incumbent*inflation_l";

. gen incumbent_unemployment_l = incumbent*unemployment_l;
(7 missing values generated)

. label var incumbent_unemployment_l "incumbent*unemployment_l";

. gen incumbent_pm = incumbent*pm;

. label var incumbent_pm "incumbent*pm";

. gen incumbent_fm = incumbent*fm;

. label var incumbent_fm "incumbent*fm";

. gen left_right2=left_right*left_right;
(39 missing values generated)

. label var left_right2 "left_right*left_right";

. gen extremist = 0;

. replace extremist=1 if family_id ==14 | family_id==40;
(87 real changes made)

. replace extremist = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist "1 if communist/socialist or far right, 0 otherwise";

. gen extremist2 = 0;

. replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
(124 real changes made)

. replace extremist2 = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";

. gen extremist_inflation_l=extremist*inflation_l;
(30 missing values generated)

. label var extremist_inflation "extremist*inflation_l";

. gen extremist_unemployment_l=extremist*unemployment_l;
(16 missing values generated)

. label var extremist_unemployment_l "extremist*unemployment_l";

. tabulate language, gen(l);

   language |      Freq.     Percent        Cum.
------------+-----------------------------------
      Dutch |        102       24.23       24.23
    English |         85       20.19       44.42
     French |         36        8.55       52.97
     German |         46       10.93       63.90
    Italian |         54       12.83       76.72
 Portuguese |         50       11.88       88.60
    Spanish |         48       11.40      100.00
------------+-----------------------------------
      Total |        421      100.00

. *     ****************************************************************  *;
. *      Change graph scheme                                                  *;
. *     ****************************************************************  *;
. *ssc install scheme-burd, replace;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *       Produce Figure 6                                                *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. set obs 10000;
number of observations (_N) was 421, now 10,000

. bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent inflation_l incumbent_pm incumbent_inflation_l extre
> mist, fe;
(running xtreg on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Fixed-effects (within) regression               Number of obs      =       391
Group variable: language                        Number of groups   =         7

R-sq:  within  = 0.2228                         Obs per group: min =        31
       between = 0.4746                                        avg =      55.9
       overall = 0.0015                                        max =       100

                                                Wald chi2(5)       =    107.72
corr(u_i, Xb)  = -0.2237                        Prob > chi2        =    0.0000

                                     (Replications based on 64 clusters in election_id)
---------------------------------------------------------------------------------------
                      |   Observed   Bootstrap                         Normal-based
   positive_sentiment |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------------+----------------------------------------------------------------
            incumbent |   .0522727   .1128164     0.46   0.643    -.1688433    .2733888
          inflation_l |  -.0404941    .014497    -2.79   0.005    -.0689076   -.0120806
         incumbent_pm |   .2331414   .0804999     2.90   0.004     .0753646    .3909183
incumbent_inflation_l |   .0379998   .0158698     2.39   0.017     .0068956    .0691041
            extremist |  -.4713886   .1036157    -4.55   0.000    -.6744716   -.2683056
                _cons |   1.899274   .2017465     9.41   0.000     1.503858     2.29469
----------------------+----------------------------------------------------------------
              sigma_u |  1.4322672
              sigma_e |  .64877972
                  rho |  .82974785   (fraction of variance due to u_i)
---------------------------------------------------------------------------------------

. matrix b=e(b);

. matrix V=e(V);

. scalar b1=b[1,1];

. scalar b3=b[1,3];

. scalar b4=b[1,4];

. scalar varb1=V[1,1];

. scalar varb3=V[3,3];

. scalar varb4=V[4,4];

. scalar covb1b3=V[1,3];

. scalar covb1b4=V[1,4];

. scalar list b1 b3 b4 varb1 varb3 varb4 covb1b3 covb1b4;
        b1 =  .05227275
        b3 =  .23314143
        b4 =  .03799985
     varb1 =  .01272754
     varb3 =  .00648023
     varb4 =  .00025185
   covb1b3 = -.00430839
   covb1b4 = -.00130624

. vce;

Covariance matrix of coefficients of xtreg model

        e(V) |  incumbent  inflatio~l  incumbe~pm  incumb~n_l   extremist       _cons 
-------------+------------------------------------------------------------------------
   incumbent |  .01272754                                                             
 inflation_l |  .00043491   .00021016                                                 
incumbent_pm | -.00430839   -.0001831   .00648023                                     
incumben~n_l | -.00130624  -.00012115   .00019051   .00025185                         
   extremist |   .0041488  -.00020621   .00134236  -.00043616   .01073621             
       _cons | -.00945857  -.00067883   .00341369   .00108071  -.01080494   .04070167 

. generate MV=(_n-100)/100;

. replace MV=. if _n>3000;
(7,000 real changes made, 7,000 to missing)

. gen conbx=b1+b3+b4*MV if _n<3000;
(7,001 missing values generated)

. gen consx=sqrt(varb1+varb3*1+varb4*(MV^2)+2*covb1b3+2*MV*covb1b4) if _n<3000;
(7,001 missing values generated)

. gen ax=1.96*consx;
(7,001 missing values generated)

. gen upperx=conbx+ax;
(7,001 missing values generated)

. gen lowerx=conbx-ax;
(7,001 missing values generated)

. graph twoway hist inflation_l, percent color(gs13) lcolor(white) yaxis(2) 
>     || line upperx MV, color(ebblue) clpattern(longdash) 
>     || line lowerx MV, color(ebblue) clpattern(longdash)  
>     || line conbx MV,color(black) lwidth(medthick) legend(off) clpattern(solid)   
>     ytitle("Effect of Incumbency on Positive Sentiment", size(2.5)) 
>     title("", size(3)) subtitle("", size(3)) xtitle("Inflation", size(2.5)) 
>     xscale(titlegap(4)) yscale(titlegap(4)) 
>     || function y = 0, range(-1 29) clpatter(shortdash) color(black) 
>     ||, xlabel(0 5 10 15 20 25 30, tlcolor(black) labcolor(black) labsize(2)) 
>     ylabel(-0.5 0 0.5 1 1.5 2.0, tlcolor(black) labcolor(black) axis(1) labsize(2)) 
>     ylabel(0 5 10 15 20 25 30 35,  axis(2) tlcolor(gs13) labcolor(gs13) labsize(2)) 
>     yscale(noline alt) yscale(noline alt axis(2)) xscale(noline) legend(off) 
>     ytitle("Percentage of Inflation Observations", color(gs12) axis(2) size(2.5)) 
>     xsca(titlegap(2)) ysca(titlegap(2)) scheme(burd);

.         graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig6.pdf", replace;
(file C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig6.pdf written in PDF format)

.     *     ****************************************************************  *;
. *       Replication complete                                            *;
. *     ****************************************************************  *;
. log close;
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure6.log
  log type:  text
 closed on:  14 Jan 2019, 15:53:26
------------------------------------------------------------------------------------------------------------------------------------------------
